<template>
  <div
    class="node-attr-container"
    :style="{
      color: themeStyle[theme].textColor1
    }"
  >
    <!-- 属性标题 -->
    <div
      class="title"
      :style="{
        borderBottom: `1px solid ${themeStyle[theme].borderColor1}`
      }"
    >
      <span style="color: #0087dc">{{ '文本属性' }}</span>
      <div class="icon" :class="Nodedata.lock ? 'lockIcon' : ''">
        <template v-if="Nodedata.lock">
          <LockOutlined @click="switchLock" />
        </template>
        <template v-else>
          <UnlockOutlined @click="switchLock" />
        </template>
      </div>
    </div>

    <div class="attr-content">
      <SizeTransition>
        <Form
          :model="Nodedata"
          :label-col="{ span: 8 }"
          :wrapper-col="{ span: 16 }"
          :label-align="'left'"
          :disabled="Nodedata.lock"
          autocomplete="off"
        >
          <!-- 文本内容 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '文本内容' }}</span
              >
            </template>
            <div style="display: flex">
              <Input
                v-model:value="Nodedata.simData.plaintext.text"
                type="text"
                size="small"
                @change="handleChange"
              />
            </div>
          </FormItem>
          <!-- 文本颜色 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '文本颜色' }}</span
              >
            </template>
            <div style="display: flex">
              <ColorSelect
                v-model:color="Nodedata.simData.plaintext.fill"
                :disable="Nodedata.lock"
                :height="24"
                @change="handleChange"
              />
            </div>
          </FormItem>
          <!-- 文字大小 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '文字大小' }}</span
              >
            </template>
            <div style="display: flex">
              <Input
                v-model:value="Nodedata.simData.plaintext.fontSize"
                type="number"
                size="small"
                @change="handleChange"
              />
            </div>
          </FormItem>
          <!-- 文本加粗 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '文本加粗' }}</span
              >
            </template>
            <div style="display: flex">
              <Select
                v-model:value="Nodedata.simData.plaintext.fontWeight"
                size="small"
                @change="handleChange"
              >
                <SelectOption value="regular">
                  <span style="color: #666; font-size: 14px">正常</span>
                </SelectOption>
                <SelectOption value="bold">
                  <span style="color: #666; font-size: 14px">加粗</span>
                </SelectOption>
              </Select>
            </div>
          </FormItem>
          <!-- 文字间距 -->
          <FormItem>
            <template #label>
              <span
                class="content-item-label"
                :style="{
                  color: themeStyle[theme].textColor1
                }"
                >{{ '文字间距' }}</span
              >
            </template>
            <div style="display: flex">
              <Input
                v-model:value="Nodedata.simData.plaintext.letterSpacing"
                type="number"
                size="small"
                @change="handleChange"
              />
            </div>
          </FormItem>
        </Form>
      </SizeTransition>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onUnmounted, watch } from 'vue'
import { Nodedata, handleChange } from './nodeProTemHook'
import { useStyleStore } from '@renderer/store/globalStyle/style'
import { storeToRefs } from 'pinia'
import { LockOutlined, UnlockOutlined } from '@ant-design/icons-vue'
import SizeTransition from '@renderer/components/sizeTransition/SizeTransition.vue'
import { Form, FormItem, Input, Select, SelectOption } from 'ant-design-vue'
import ColorSelect from '@renderer/components/colorSelect/ColorSelect.vue'

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
    required: false
  }
})
Nodedata.value = props.data

watch(
  () => props.data,
  (val) => {
    if (props.data.id !== Nodedata.value.id) {
      handleChange()
    }
    Nodedata.value = props.data
  },
  {
    deep: true
  }
)
onUnmounted(() => {
  handleChange()
})

const globalStyleStore = useStyleStore()
const { theme, themeStyle } = storeToRefs(globalStyleStore)

const switchLock = (): void => {
  Nodedata.value.lock = !Nodedata.value.lock
  handleChange()
}
</script>
<style scoped lang="scss">
.node-attr-container {
  width: 100%;
  height: 100%;
  font-size: $font-size-medium;
  .title {
    padding: 3px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;

    .icon {
      margin-right: 10px;
      cursor: pointer;
      width: 25px;
      height: 25px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 5px;
      color: #7e7e7e;
    }
    .lockIcon {
      background-color: $icon-active-bgColor;
      color: $icon-active-color;
    }
  }

  .attr-content {
    padding: 5px 3px 5px 6px;
    height: calc(100% - 60px);
    user-select: none;
    :deep(.ant-form-item) {
      margin-bottom: 0px;
    }

    :deep(.basic-info-item-prefix) {
      width: 16px;
      font-size: $font-size-small;
    }
  }
}
</style>
